/*
day141
2020.1.16
*/ 
#include<string>
#include<vector>
#include<iostream>
#include<unordered_map>
using namespace std;


class Solution1 {
public:
    vector<string> findWords(vector<string>& words) 
    {
    	vector<string> res;
    	
        string s1="qwertyuiopQWERTYUIOP";
        string s2="asdfghjklASDFGHJKL";
        string s3="zxcvbnmZXCVBNM";
        
        unordered_map<char,int> m1;
        unordered_map<char,int> m2;
        unordered_map<char,int> m3;
        unordered_map<char,int> tem;
        
        for(int i=0;i<s1.size();i++) m1[s1[i]]=1;
        for(int i=0;i<s2.size();i++) m2[s2[i]]=1;
        for(int i=0;i<s3.size();i++) m3[s3[i]]=1;
        
        for(int i=0;i<words.size();i++)
        {
        	
        	string str=words[i];
        	if( m1[str[0]] != 0)	
			{
				tem=m1;
			}
        	else if( m2[str[0]] != 0)	
			{
				tem=m2;
			}
        	else 
			{
				tem=m3;
			}
        	
        	int j=1;
        	for(;j<str.size();j++)
        	{
        		if(tem[str[j]] != 1) break;
			}
			if(j==str.size()) res.push_back(str);
		}
        
        return res;
    }
};





class Solution2 {
public:
    vector<string> findWords(vector<string>& words) 
	{
        string q{"qwertyuiop"};
        string a{"asdfghjkl"};
        string z{"zxcvbnm"};
        vector<string> ans;    

        for(int i=0;i<words.size();i++)
        {
            int d=0,b=0,c=0;
            for(int j=0;j<words[i].size();j++)
            {
                if(q.find(tolower(words[i][j]))!=string::npos) b++;
                if(a.find(tolower(words[i][j]))!=string::npos) c++;
                if(z.find(tolower(words[i][j]))!=string::npos) d++;
            }
            if(b==words[i].size()||c==words[i].size()||d==words[i].size()) 
            ans.push_back(words[i]);
        }
        return ans;   
    }
};
int main()
{
	vector<string> vec={"hello"};
	Solution1 s;
	vector<string> res=s.findWords(vec);
	for(int i=0;i<res.size();i++)
	{
		cout<<res[i]<<endl;
	}
	return 0;
}
